using System;
using System.Collections.Generic;
using System.Text;

namespace FrameworkX.ObjectSpace.Validation
{
    internal class Util
    {
        internal static string GetSpacedStringFromWordCapitalizedString(string source)
        {
            if (source == null)
            {
                return string.Empty;
            }
            if (source.Length == 0)
            {
                return string.Empty;
            }

            StringBuilder sb = new StringBuilder();
            bool lastCharWasCapital = true;
            for (int i = 0; i <= source.Length - 1; i++)
            {
                char c = source[i];
                if (c >= 65 && c <= 90)
                {
                    if (!lastCharWasCapital)
                    {
                        sb.Append(" ");
                        sb.Append(c, 1);
                    }
                    else
                    {
                        sb.Append(c, 1);
                    }
                    lastCharWasCapital = true;
                }
                else
                {
                    sb.Append(c, 1);
                    lastCharWasCapital = false;
                }
            }
            return sb.ToString();
        }

    }
}
